﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace GraphDrawer {
	public partial class DatabaseModelSelector : UserControl {
		public string modelML;

		private DataProvider.DataProviderServiceSoapClient cl = new DataProvider.DataProviderServiceSoapClient();

		public DatabaseModelSelector() {
			InitializeComponent();

			Description.Text = Resource.DatabaseModelSelector;

			cl.GetAvailableDiseasesCompleted +=
				new EventHandler<DataProvider.GetAvailableDiseasesCompletedEventArgs>
					(cl_GetAvailableDiseasesCompleted);

			cl.GetDiseaseCompleted +=
				new EventHandler<DataProvider.GetDiseaseCompletedEventArgs>
					(cl_GetDiseaseCompleted);

			cl.GetAvailableDiseasesAsync();
		}

		public void Init() {
			if (diseasesBox.Items.Count > 0)
				WizardMenu.PopUp.btnOk.IsEnabled = true;
		}

		void cl_GetAvailableDiseasesCompleted(object sender, DataProvider.GetAvailableDiseasesCompletedEventArgs e) {
			diseasesBox.Items.Clear();

			foreach (var item in e.Result)
				diseasesBox.Items.Add(item);
			
			if (diseasesBox.Items.Count > 0)
				diseasesBox.SelectedItem = diseasesBox.Items[0];
		}

		void cl_GetDiseaseCompleted(object sender, DataProvider.GetDiseaseCompletedEventArgs e) {
			modelML = e.Result[0];
			diseaseDescription.Text = e.Result[1];
		}

		private void DiseaseBox_SelectionChanged(object sender, SelectionChangedEventArgs e) {
			if (diseasesBox.SelectedItem != null)
				cl.GetDiseaseAsync(diseasesBox.SelectedItem.ToString());
		}
	}
}
